package com.forlove.app.qselect.index.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.forlove.app.R;
import com.forlove.app.common.base.mvp.presenter.IBasePresenter;
import com.forlove.app.common.utils.LogUtil;
import com.forlove.app.common.utils.MyTimeUtils;
import com.forlove.app.common.widget.recyview.BaseRecyclerAdapter;
import com.forlove.app.common.widget.recyview.ViewHolder;
import com.forlove.app.qselect.index.entity.FriendCircleInfoEntity;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * 好友被圈列表的adapter
 * Created by yjl on 2017/10/11.
 */

public class FriendCircleAdapter extends BaseRecyclerAdapter<FriendCircleInfoEntity> {
    private IBasePresenter basePresenter;

    public FriendCircleAdapter(Context context, int itemView, List<FriendCircleInfoEntity> mDatas, IBasePresenter basePresenter) {
        super(context, itemView, mDatas);
        this.basePresenter = basePresenter;
    }

    @Override
    protected void convertView(ViewHolder holder, FriendCircleInfoEntity entity, int position) {
        if (basePresenter != null) {
            basePresenter.loadImageView(mContext, holder.getView(R.id.image_index_photo),
                    entity.img, R.mipmap.image_mine_friend_avatar);
        }
        holder.setText(R.id.text_friend_name, entity.to_realname);
        holder.setText(R.id.text_circle_info, entity.name);
        if (entity.mSex == 2) {
            holder.setBackgroundRes(R.id.image_from_sex, R.mipmap.icon_red_diamond_index);
        } else if (entity.mSex == 1) {
            holder.setBackgroundRes(R.id.image_from_sex, R.mipmap.icon_blue_diamond_index);
        }
        holder.setText(R.id.text_friend_info, entity.info);
//        if (entity.isread == 0) {
//            holder.setVisible(R.id.view_new_info, true);
//        } else {
//            holder.setVisible(R.id.view_new_info, false);
//        }
        Date data = new Date(entity.addtime * 1000);
        String time = "";
        try {
            time = MyTimeUtils.friendlyFormat(data);
        } catch (ParseException e) {
            LogUtil.e(e.getMessage());
        }
        if (TextUtils.isEmpty(time)) {
            time = MyTimeUtils.formatDate(new Date(entity.addtime * 1000), "MM月DD日HH时mm分");
        }
        holder.setText(R.id.text_circle_time, time);

    }
}
